﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Conference.Logic.Base
{
    /// <summary>
    /// Represents a type of an item
    /// </summary>
    public enum ItemType
    {
        None, // invalid option
        Default, // needs a duration
        Lightning, // according with parameter
        Launch, // special item
        Network // special item
    }

    /// <summary>
    /// Base class that represents a generic item
    /// </summary>
    public abstract class Item
    {
        #region Attributes
        private string description;
        private TimeSpan duration;
        private ItemType type;
        #endregion

        #region Properties
        /// <summary>
        /// Return the item description. Read only property.
        /// </summary>
        public string Description
        {
            get { return this.description; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                    this.description = value;
                else
                    throw new Exception("Invalid description value!");
            }
        }

        /// <summary>
        /// Return the item duration. Read only property.
        /// </summary>
        public TimeSpan Duration
        {
            get 
            { 
                return this.duration; 
            }
            set
            {
                if (value.Hours.Equals(1) || !value.Minutes.Equals(0))
                {
                    this.duration = this.duration.Add(value);
                }
            }
        }

        public virtual ItemType Type
        {
            get { return this.type; }
            set
            {
                if (value != ItemType.None)
                    this.type = value;
                else
                    throw new InvalidCastException("Invalid value parameter!");
            }
        }        
        #endregion

        #region Constructor
        /// <summary>
        /// Create a new item object
        /// </summary>
        /// <param name="description">Title</param>
        /// <param name="type">Type (default, lightning)</param>
        /// <param name="duration">Duration lenght</param>
        public Item(string description, ItemType type, TimeSpan duration)
        {
            try
            {
                this.Description = description;
                this.Duration = duration;
                this.type = type;
            }
            catch (Exception ex)
            {
                throw ex ;
            }
        }

        /// <summary>
        /// Create a new item object
        /// </summary>
        /// <param name="description">Title</param>
        /// <param name="duration">Duration length</param>
        public Item(string description, TimeSpan duration)
        {
            try
            {
                this.Description = description;
                this.Duration = duration;
                this.type = ItemType.Default;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// Create a new item object
        /// </summary>
        /// <param name="description">Title</param>
        public Item(string description)
        {
            try
            {
                this.Description = description;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}
